 /***************************************************************************
 *   Copyright (C) 2010 by ZhangShine , All Rights Reserved                                  
 *   zhangshine0125@gmail.com                                              
 *                                                                         
 *   This program is free software; you can redistribute it and/or modify  
 *   it under the terms of the GNU General Public License as published by  
 *   the Free Software Foundation; either version 2 of the License, or     
 *   (at your option) any later version.                                   
 *                                                                         
 *   This program is distributed in the hope that it will be useful,       
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
 *   GNU General Public License for more details.                          
 *                                                                         
 *   You should have received a copy of the GNU General Public License     
 *   along with this program; if not, write to the                         
 *   Free Software Foundation, Inc.,                                       
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             
 ***************************************************************************/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "account.h"
#include "sendstatusdialog.h"
#include "dealwebkitevent.h"
#include "configuration.h"
#include "aboutdialog.h"
#include "notifer.h"
#include <QMainWindow>
#include <QSystemTrayIcon>

namespace Ui {
    class MainWindow;
}

/*! \class MainWindow
 * \brief 主窗口
 *
 *
 */
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(Account *account);
    ~MainWindow();
    void closeEvent(QCloseEvent *event);
    
public slots:
    void prepare();
    void preHtml();
    void newWeiboButtonClicked();
    void homePageButtonClicked();
    void myWeiboPageButtonClicked();
    void atMePageButtonClicked();
    void commentPageButtonClicked();
    void favouritePageButtonClicked();
    void messagePageButtonClicked();
    void configureButtonClicked();
    void getOthersTimelineByScreenName(QString screenName, int page=1);
    void getMoreHomePageStatus(int page=1, int feature=0);
    void getMoreUserPageStatus(int page=1, int feature=0);
    void getMoreAtMePageStatus(int page=1);
    void getMoreCommentsPageStatus(int page=1);
    void getMoreFavoritePageStatus(int page=1);
    void getMoreDirectMessagePageStatus(int page=1);
    void refreshStatus();
    void updateIcon(QPixmap *pixmap, int unreadCount);
    void refreshSystemTrayIconTooltip();
    void showPictueInWidget(QString bigUrl, QString midUrl);
    void systemTrayIconAction(QSystemTrayIcon::ActivationReason reason);
    void aboutQLisa();//关于QLisa
    void feedBackToQLisa();//建议与反馈
    
    void addJavaScriptObject();
    void dealWebkitEventDisconnectThenConnect();
private:
    Ui::MainWindow *ui;
    Account *account;
    Configuration *conf;
    QTimer *timer;
    DealWebkitEvent *dealWebkitEvent;
    QString basicHtml;
    QString homePageHtml;
    QString atMePageHtml;
    QString myWeiboPageHtml;
    QString favoritePageHtml;
    QString commentPageHtml;
    QString directMessagePageHtml;
    bool homePageHtmlReady;
    bool homePageStatusReady;
    bool atMePageHtmlReady;
    bool atMePageStatusReady;
    bool myWeiboPageHtmlReady;
    bool myWeiboPageStatusReady;
    bool favoritePageHtmlReady;
    bool favoritePageStatusReady;
    bool commentPageHtmlReady;
    bool commentPageStatusReady;
    bool directMessagePageHtmlReady;
    bool directMessagePageStatusReady;
    int statusUnread;
    int commentsUnread;
    int directMessageUnread;
    int newFollower;
    int atMeMentionsUnread;
    
    QSystemTrayIcon *systemTrayIcon;//系统托盘
    QMenu *systemTrayMenu;//系统托盘右键菜单
    QAction *quitAction;
    QAction *restoreAction;
    /* more button */
    QMenu *moreMenu;
    QAction *about;//关于
    QAction *feedBack;//反馈
private:
    void createSystemTrayIcon();
    void setWebviewHtml(QString html);
protected:
    void resizeEvent(QResizeEvent *);
};

#endif // MAINWINDOW_H
